package org.new9uy.tetris.model.tetrimino;

import org.new9uy.tetris.GameConstants;
import org.new9uy.tetris.model.Matrix;
import org.new9uy.tetris.model.Mino;

public class T extends Tetrimino
{

    public T(Matrix mtx)
    {
        super(
                new Mino[]
        {
            mtx.getMino(5, 20),
            mtx.getMino(6, 20),
            mtx.getMino(7, 20),
            mtx.getMino(6, 19)
        }, GameConstants.TETRIMINO_COLOR_T);
    }

    @Override
    public Mino refer()
    {
        return mino(1);
    }

    @Override
    public Mino center(Matrix mtx)
    {
        return refer();
    }

    @Override
    public Mino[] rotate(Matrix mtx)
    {
        Mino center = center(mtx);
        Mino[] ret = new Mino[4];
        int x, y, x2, y2;

        for (int i = 0; i < 4; i++)
        {
            x = mino(i).getX() - center.getX();
            y = mino(i).getY() - center.getY();
            //90� Rotation (rotation matrix):
            x2 = y;
            y2 = -x;

            ret[i] = mtx.getMino(x2 + center.getX(), y2 + center.getY());
        }

        return ret;
    }
}